/*
 * @lc app=leetcode.cn id=1752 lang=javascript
 *
 * [1752] 检查数组是否经排序和轮转得到
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {boolean}
 */
var check = function (nums) {
  if(nums.length === 1) return true;
  const arr = nums.concat(nums);
  let n = 2;
  let num = 1;
  for (let i = 1; i < arr.length; i++) {
    if (arr[i] >= arr[i - 1]) {
      num++;
      if (num === nums.length) {
        return true;
      }
    } else {
      n--;
      if (n === 0) {
        return false;
      }
      num = 1;
    }
  }
};
// @lc code=end
